home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / RKMLibsPrgs / intuition / screens / publicscreen.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  4KB  |  130 lines

  1. ;/* publicscreen.c - open a screen with the pens from a public screen.
  2. lc -b1 -cfist -v -y -j73 publicscreen
  3. blink FROM LIB:c.o publicscreen.o TO publicscreen LIB LIB:lc.lib LIB:amiga.lib
  4. quit
  5. */
  6.  
  7. /*
  8. Copyright (c) 1992 Commodore-Amiga, Inc.
  9.  
  10. This example is provided in electronic form by Commodore-Amiga, Inc. for
  11. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  12. published by Addison-Wesley (ISBN 0-201-56774-1).
  13.  
  14. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  15. information on the correct usage of the techniques and operating system
  16. functions presented in these examples.  The source and executable code
  17. of these examples may only be distributed in free electronic form, via
  18. bulletin board or as part of a fully non-commercial and freely
  19. redistributable diskette.  Both the source and executable code (including
  20. comments) must be included, without modification, in any copy.  This
  21. example may not be published in printed form or distributed with any
  22. commercial product.  However, the programming techniques and support
  23. routines set forth in these examples may be used in the development
  24. of original executable software products for Commodore Amiga computers.
  25.  
  26. All other rights reserved.
  27.  
  28. This example is provided "as-is" and is subject to change; no
  29. warranties are made.  All use is at your own risk. No liability or
  30. responsibility is assumed.
  31. */
  32.  
  33. #define INTUI_V36_NAMES_ONLY
  34.  
  35. #include <exec/types.h>
  36. #include <intuition/intuition.h>
  37. #include <intuition/screens.h>
  38.  
  39. #include <clib/exec_protos.h>
  40. #include <clib/dos_protos.h>
  41. #include <clib/intuition_protos.h>
  42.  
  43. #ifdef LATTICE
  44. int CXBRK(void)    { return(0); }  /* Disable Lattice CTRL/C handling */
  45. int chkabort(void) { return(0); }  /* really */
  46. #endif
  47.  
  48. VOID usePubScreenPens(void);
  49.  
  50. struct Library *IntuitionBase;
  51.  
  52. /* main(): open libraries, clean up when done.
  53. */
  54. VOID main(int argc, char **argv)
  55. {
  56. IntuitionBase = OpenLibrary("intuition.library",0);
  57. if ( IntuitionBase != NULL )
  58.     {
  59.     /* Check the version number; Release 2 is */
  60.     /* required for public screen functions   */
  61.     if (IntuitionBase->lib_Version >= 37)
  62.         {
  63.         usePubScreenPens();
  64.         }
  65.     CloseLibrary(IntuitionBase);
  66.     }
  67. }
  68.  
  69. /* Open a screen that uses the pens of an existing public screen
  70. ** (the Workbench screen in this case).
  71. */
  72. VOID usePubScreenPens(void)
  73. {
  74. struct Screen *my_screen;
  75. struct TagItem screen_tags[2];
  76. UBYTE *pubScreenName = "Workbench";
  77.  
  78. struct Screen *pub_screen = NULL;
  79. struct DrawInfo *screen_drawinfo = NULL;
  80.  
  81. /* Get a lock on the Workbench screen */
  82. pub_screen = LockPubScreen(pubScreenName);
  83. if ( pub_screen != NULL )
  84.     {
  85.     /* get the DrawInfo structure from the locked screen */
  86.     screen_drawinfo = GetScreenDrawInfo(pub_screen);
  87.     if ( screen_drawinfo != NULL)
  88.         {
  89.         /* the pens are copied in the OpenScreenTagList() call,
  90.         ** so we can simply use a pointer to the pens in the tag list.
  91.         **
  92.         ** This works better if the depth and colors of the new screen
  93.         ** matches that of the public screen.  Here we are forcing the
  94.         ** workbench screen pens on a monochrome screen (which may not
  95.         ** be a good idea).  You could add the tag:
  96.         **      (SA_Depth, screen_drawinfo->dri_Depth)
  97.         */
  98.         screen_tags[0].ti_Tag  = SA_Pens;
  99.         screen_tags[0].ti_Data = (ULONG)(screen_drawinfo->dri_Pens);
  100.         screen_tags[0].ti_Tag  = TAG_END;
  101.         screen_tags[0].ti_Data = NULL;
  102.  
  103.         my_screen = OpenScreenTagList(NULL, screen_tags);
  104.         if (my_screen != NULL)
  105.             {
  106.             /* We no longer need to hold the lock on the public screen
  107.             ** or a copy of its DrawInfo structure as we now have our
  108.             ** own screen.  Release the screen.
  109.             */
  110.             FreeScreenDrawInfo(pub_screen,screen_drawinfo);
  111.             screen_drawinfo = NULL;
  112.             UnlockPubScreen(pubScreenName,pub_screen);
  113.             pub_screen = NULL;
  114.  
  115.             Delay(90);   /* should be rest_of_program */
  116.  
  117.             CloseScreen(my_screen);
  118.             }
  119.         }
  120.     }
  121.  
  122. /* These are freed in the main loop if OpenScreenTagList() does
  123. ** not fail.  If something goes wrong, free them here.
  124. */
  125. if ( screen_drawinfo != NULL )
  126.     FreeScreenDrawInfo(pub_screen,screen_drawinfo);
  127. if ( pub_screen!= NULL )
  128.     UnlockPubScreen(pubScreenName,pub_screen);
  129. }
  130.